package com.le.tester.webpage;


import com.le.tester.utils.DateTimeUtilFor8;
import org.apache.commons.lang3.StringUtils;

import java.time.Duration;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.stream.Collectors;

/**
 * createTime：2021/10/29 17:24
 * description：test
 */
public class Tester {



    private static final String MESSAGE = "taobao";

//    public Tester() {
//        super();
//        System.out.println("super order");
//        super();
//    }

    //switch获取值
    public static int getValue(int i) {
        int result = 0;
        switch (i) {
            case 1:
                result = result + i;
            case 2:
                result = result + i * 2;
                break;
            case 3:
                result = result + i * 3;
        }
        return result;
    }

    public static void compareString() {
        String a = "tao" + "bao";
        String b = "tao";
        String c = "bao";
        System.out.println(a == MESSAGE);

        System.out.println(b + c);

        //新的引用地址了，导致比较的值为F
        System.out.println((b + c) == MESSAGE);
    }

    public String getTimeNodeWithSpace(String businessHours, Integer durations, Integer spacing) {
        //开始计算节点
        String[] businessHoursItem = businessHours.split("-");
        //startHour
        String startHour = businessHoursItem[0];
        //endHour
        String endHour = businessHoursItem[1];
        List<String> resultList = new ArrayList<>();
        //开始时间
        if (4 == startHour.length()) {
            startHour = "0" + startHour + ":" + "00";
        } else {
            startHour = startHour + ":" + "00";
        }
        //结束时间
        if (4 == endHour.length()) {
            endHour = "0" + endHour + ":" + "00";
        } else {
            endHour = endHour + ":" + "00";
        }

        LocalTime startHourParsed = LocalTime.parse(startHour);
        LocalTime endHourParsed = LocalTime.parse(endHour);
        Duration duration = Duration.between(startHourParsed, endHourParsed);
        long spacingLength = duration.toMinutes() / (durations + spacing);
        for (int i = 0; i < spacingLength; i++) {
            LocalTime resultTime = startHourParsed.plusMinutes((durations + spacing) * i);
            String resultTimeStr = resultTime.format(DateTimeFormatter.ofPattern(DateTimeUtilFor8.TIME_FORMAT_HOUR_MIN));
//            resultTime = resultTime.plusMinutes(spacingTime + durationTime);
//            resultTimeStr = resultTime.format(DateTimeFormatter.ofPattern("HH:mm"));
            //String resultTimeStr = businessEndTimeParse.format(DateTimeFormatter.ofPattern("HH:mm"));
            resultList.add(resultTimeStr);
        }
        return StringUtils.join(resultList, ",");
    }

    public List<String> collectionCompare() {
        List<String> oneList = new ArrayList<>();
        List<String> tweList = new ArrayList<>();
        oneList.add("1");
        oneList.add("2");
        oneList.add("3");
        oneList.add("4");


        tweList.add("1");
        tweList.add("4");
        tweList.add("5");
        tweList.add("6");

        List<String> collect = oneList.stream().filter(tweList::contains).collect(Collectors.toList());
        List<String> collect1 = oneList.stream().filter(item -> !tweList.contains(item)).collect(Collectors.toList());


        System.out.println("collect" + collect);
        System.out.println("collect1" + collect1);

        return null;
    }

    public static void main(String[] args) {
//计算时间节点
        Tester tester = new Tester();
        String timeNodeWithSpace = tester.getTimeNodeWithSpace("8:00-20:00", 30, 10);
        System.out.println(timeNodeWithSpace);

        tester.collectionCompare();

    }
}
